// components/recording-popup/recording-popup.ts
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        visible: {
            type: Boolean,
            value: false,
            observer(newVal) {
                // 在这里处理值变化逻辑
                if (newVal) {
                    this.startAnimation(true);
                } else {
                    this.hidePopup();
                }
            },
        },
        cancel: {
            type: Boolean,
            value: false,
            observer(newVal) {
                // 在这里处理值变化逻辑
                if (newVal) {
                    this.setData({ cancelFlag: true });
                } else {
                    this.setData({ cancelFlag: false });
                }
            },
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        animation: null as any | null, // WechatMiniprogram.Animation
        cancelFlag: false,
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onTouchstart() {
            console.log("触摸");
        },
        onTouchend(e: any) {
            console.log("结束", e);
        },
        // onTouchMove(e: any) {
        //     console.log("移动", e);
        // },
        popupTouchmove(e: any) {
            console.log(e, "移动");
        },
        bindtouchstart(e: any) {
            console.log(e, "开始");
        },
        bindtouchend(e: any) {
            console.log(e, "移动结束");
        },
        // 隐藏弹出层
        hidePopup() {
            console.log("手指移入");
            this.startAnimation(false);
            this.triggerEvent("hidePopup");
            // setTimeout(() => {
            //     this.triggerEvent("hidePopup");
            // }, 300); // 延迟以等待动画结束
        },
        // 开始动画
        startAnimation(show: boolean) {
            const animation = wx.createAnimation({
                duration: 300,
                timingFunction: "ease",
            });
            if (show) {
                animation.scale(1).step();
            } else {
                animation.scale(0).step();
            }
            this.setData({ animation: animation.export() });
        },
    },
});
